package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.base.BaseController;
import com.shop.entity.UserCoupon;
import com.shop.result.ResultVO;
import com.shop.service.UserCouponService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author XCH
 * @date 2025 - 05 - 19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/coupon")
public class UserCouponController extends BaseController {
    private final UserCouponService userCouponService;
    @RequestMapping("/listUserCoupon")
    public ResultVO<PageInfo<UserCoupon>> listUserCoupon(@RequestParam("userId") Integer userId, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<UserCoupon> userCouponPageInfo = userCouponService.listUserCoupon(userId,pageNo, pageSize);
        return success(userCouponPageInfo);
    }
    @PostMapping("/getUserCouponById")
    public ResultVO<UserCoupon> getUserCouponById(@RequestParam("id") Integer id) {
        UserCoupon userCoupon = userCouponService.getUserCouponById(id);
        return success(userCoupon);
    }

    @PostMapping("/addUserCoupon")
    public ResultVO<UserCoupon> addUserCoupon(@RequestParam("userId")Integer userId, @RequestParam("couponId")Integer couponId, @RequestParam("used")Integer used) {
        userCouponService.addUserCoupon(userId, couponId, used);
        return success(200,"添加成功");
    }

    @PostMapping("/updateUserCoupon")
    public ResultVO<Integer> updateUserCoupon(@ModelAttribute UserCoupon userCoupon) {
        userCouponService.updateUserCoupon(userCoupon);
        return success(200,"修改成功");
    }

    @PostMapping("/deleteUserCoupon")
    public ResultVO<Integer> deleteUserCoupon(@RequestParam("id") Integer id) {
        userCouponService.deleteUserCoupon(id);
        return success(200,"删除成功");
    }
    @GetMapping("/getCount")
    public ResultVO<Integer> getTotal(@RequestParam("userId") Integer userId) {
        int total = userCouponService.getTotal(userId);
        return success(total);
    }
}
